home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #14 / Monster Media No. 14 (April 1996) (Monster Media, Inc.).ISO / prog_bas / pclvbw10.zip / LOGLINE.BAS < prev    next >
BASIC Source File  |  1996-02-16  |  6KB  |  245 lines

  1. ' LOGLINE.BAS
  2. Option Explicit
  3.  
  4. Dim FatalFlag As Integer
  5. Dim Code As Integer
  6.  
  7. Sub Aborting ()
  8.   Dim Code As Integer
  9.   LOGIN.Print "Fatal Error, Aborting..."
  10.   Code = SioDone(ThePort)
  11.   End
  12. End Sub
  13.  
  14. Sub DisplayChar (ByVal C As Integer)
  15.   Dim Row As Integer
  16.   Dim Col As Integer
  17.   C = &H7F And C
  18.   'process char
  19.   If C = 13 Then
  20.     'carriage control
  21.     CurrentCol = 0
  22.     'plus assumed line feed
  23.     If CurrentRow < 23 Then
  24.       CurrentRow = CurrentRow + 1
  25.       'print CR+LF
  26.       LOGIN.Print
  27.     Else
  28.       'scroll !
  29.       LOGIN.Cls
  30.       For Row = 0 To 22
  31.         'print row
  32.         ScreenBuffer(Row) = ScreenBuffer(Row + 1)
  33.         LOGIN.Print ScreenBuffer(Row)
  34.       Next Row
  35.       'clear bottom row
  36.       ScreenBuffer(23) = Space$(80)
  37.     End If
  38.   ElseIf C = 10 Then
  39.     'throw away line feeds
  40.   Else
  41.     'not CR or LF
  42.     CurrentCol = CurrentCol + 1
  43.     If CurrentCol > 79 Then
  44.       'throw away !
  45.       Exit Sub
  46.     Else
  47.       'save in screen buffer & display
  48.       Mid$(ScreenBuffer(CurrentRow), CurrentCol, 1) = Chr$(C)
  49.       LOGIN.Print Chr$(C);
  50.     End If
  51.   End If
  52. End Sub
  53.  
  54. Sub DisplayString (Text As String)
  55.   Dim I As Integer
  56.   Dim Length As Integer
  57.   Length = Len(Text)
  58.   For I = 1 To Length
  59.     Call DisplayChar(Asc(Mid$(Text, I, 1)))
  60.   Next I
  61.   Call DisplayChar(13)
  62. End Sub
  63.  
  64. Sub GetIncoming ()
  65.   Dim I As Integer
  66.   Dim TheChar As Integer
  67.   Dim Code As Integer
  68.   'is modem I/O (MIO) running ?
  69.   If MIOstate Then
  70.     'MIO is running
  71.     TheChar = mioDriver(ThePort)
  72.     If TheChar = MIO_IDLE Then
  73.       'time to go to next MIO state (since driver is idle)
  74.       Select Case MIOstate
  75.         '*** HANDSHAKE states ***
  76.         Case Handshake_1
  77.           'send "AT" to modem
  78.           Code = mioSendTo(ThePort, 100&, "!AT!")
  79.           MIOstate = Handshake_2
  80.         Case Handshake_2
  81.           'expect "OK" back
  82.           Code = mioWaitFor(ThePort, 3000&, 1, "OK")
  83.           MIOstate = Handshake_3
  84.         Case Handshake_3
  85.           'did we get expected result ("OK")
  86.           If mioResult(ThePort) Then
  87.             DisplayString (">>>OK was received")
  88.           Else
  89.             DisplayString (">>>OK was NOT received!")
  90.           End If
  91.           'all done
  92.           MIOstate = 0
  93.           LOGIN.menuStart.Enabled = True
  94.           LOGIN.menuBREAK.Enabled = False
  95.         '*** DIAL states ***
  96.         Case Dial_1
  97.           'dial modem
  98.           Code = mioSendTo(ThePort, 100&, "!ATDT1,205,880,9748!")
  99.           MIOstate = Dial_2
  100.         Case Dial_2
  101.           'expect "CONNECT" back (wait up to 60 seconds)
  102.           If mioWaitFor(ThePort, 60000, 1, "CONNECT") Then
  103.             MIOstate = Dial_3
  104.           Else
  105.             'error!
  106.             DisplayString (">>>mioWaitFor fails!")
  107.           End If
  108.         Case Dial_3
  109.           'did we get expected result ("CONNECT")
  110.           If mioResult(ThePort) Then
  111.             DisplayString (">>>CONNECT was received")
  112.           Else
  113.             DisplayString (">>>CONNECT was NOT received!")
  114.           End If
  115.           'all done
  116.           MIOstate = 0
  117.           LOGIN.menuBREAK.Enabled = False
  118.           LOGIN.menuStart.Enabled = True
  119.       End Select
  120.     Else
  121.       'MIO is not IDLE
  122.       If TheChar <> MIO_RUNNING Then
  123.         Call DisplayChar(TheChar)
  124.       End If
  125.     End If
  126.   Else
  127.   'MIO not in use
  128.     For I = 1 To 82
  129.       TheChar = SioGetc(ThePort, 0)
  130.       If TheChar > 0 Then
  131.         Call DisplayChar(TheChar)
  132.         '''Call DisplayString("{" + Hex$(TheChar) + "}")
  133.       Else
  134.         Exit For
  135.       End If
  136.     Next I
  137.   End If
  138. End Sub
  139.  
  140. Sub GoOffLine ()
  141.   Dim Code As Integer
  142.   OnLineFlag = 0
  143.   'shut down port
  144.   Code = SioDone(ThePort)
  145.   'free DOS memory
  146.   If TxSelector <> 0 Then
  147.     Code = GlobalPageUnlock(TxSelector)
  148.     Code = GlobalDosFree(TxSelector)
  149.     TxSelector = 0
  150.   End If
  151.   If RxSelector <> 0 Then
  152.     Code = GlobalPageUnlock(RxSelector)
  153.     Code = GlobalDosFree(RxSelector)
  154.     RxSelector = 0
  155.   End If
  156.  
  157. End Sub
  158.  
  159. Sub GoOnLine ()
  160.   Dim I As Integer
  161.   Dim dwValue As Long
  162.   Dim dwSize As Long
  163.   Dim SizeCode As Integer
  164.   If OnLineFlag Then
  165.     Exit Sub
  166.   End If
  167.   'set size.
  168.   dwSize = 512&
  169.   SizeCode = Size512
  170.   'allocate RX buffer
  171.   dwValue = GlobalDosAlloc(dwSize)
  172.   If dwValue Then
  173.     'get selector
  174.     RxSelector = (&HFFFF& And dwValue)
  175.     LockCount = GlobalPageLock(RxSelector)
  176.     If LockCount = 0 Then
  177.       LOGIN.Print "LockCount error"
  178.       End
  179.     End If
  180.   End If
  181.   'allocating RX buffer
  182.   Code = SioRxBuf(ThePort, RxSelector, SizeCode)
  183.   If Code < 0 Then
  184.     LOGIN.Print "Cannot allocate RX buffer"
  185.     End
  186.   End If
  187.   'allocate TX buffer
  188.   dwValue = GlobalDosAlloc(dwSize)
  189.   If dwValue Then
  190.     'get selector
  191.     TxSelector = (&HFFFF& And dwValue)
  192.     LockCount = GlobalPageLock(TxSelector)
  193.     If LockCount = 0 Then
  194.       LOGIN.Print "LockCount error"
  195.       End
  196.     End If
  197.   End If
  198.   Code = SioTxBuf(ThePort, TxSelector, SizeCode)
  199.   If Code < 0 Then
  200.     LOGIN.Print "Cannot allocate TX buffer"
  201.     End
  202.   End If
  203.   'reset the port
  204.   Code = SioReset(ThePort, TheBaudCode)
  205.   If Code < 0 Then
  206.     LOGIN.Print "ERROR: SioReset returns" + Str$(Code)
  207.     End
  208.   End If
  209.   Call DisplayString("COM" + LTrim$(Str$(1 + ThePort)) + " reset")
  210.   'set DTR & RTS
  211.   Code = SioDTR(ThePort, Asc("S"))
  212.   Code = SioRTS(ThePort, Asc("S"))
  213.   'turn on hardware flow control
  214.   Code = SioFlow(ThePort, 18)
  215.   Call DisplayString("RTS/CTS flow control on")
  216.   'turn on UART FIFO if 16550
  217.   Code = SioFIFO(ThePort, LEVEL_8)
  218.   If Code > 0 Then
  219.     Call DisplayString("16550 Detected")
  220.   End If
  221.   ' set parms
  222.   Code = SioParms(ThePort, TheParity, TheStopBits, TheDataBits)
  223.   ' we're online !
  224.   OnLineFlag = 1
  225. End Sub
  226.  
  227. Sub ShowConfig ()
  228.   Dim A As String
  229.   Dim B As String
  230.   Dim C As String
  231.   Dim D As String
  232.   Dim E As String
  233.   If OnLineFlag Then
  234.     A = " (Online)"
  235.   Else
  236.     A = " (Offline)"
  237.   End If
  238.   B = "COM" + LTrim$(Str$(ThePort + 1))
  239.   C = " @ " + BaudText(TheBaudCode) + " "
  240.   D = Str$(5 + TheDataBits) + ParityText(TheParity)
  241.   E = LTrim$(Str$(1 + TheStopBits))
  242.   LOGIN.Caption = "LOGIN: " + B + C + D + E + A
  243. End Sub
  244.  
  245.